<?php
namespace app\admin\controller;

use app\admin\validate\AdminRoleValidate;
use app\service\traits\Crud;
use app\admin\model\AdminRole as AdminRoleModel;

class AdminRole extends Base
{
    private AdminRoleModel $model;

    use Crud;

    public function initialize()
    {
        parent::initialize();
        $this->model         = new AdminRoleModel();
        $this->validateClass = AdminRoleValidate::class;
        $this->field         = 'id,name,status,role_key,role_sort,data_scope,create_time,remark';
        $this->append        = 'data_scope_text';
        $this->withSearch    = 'name,role_key,status,create_time';
    }

    public function format($list): mixed
    {
        return $list->each(function($item) {
            $item->menu_ids = $item->adminRoleMenus()->column('admin_menu_id');
        });
    }
}